package com.water.wfo.user.controller;

import com.water.wfo.component.api.entity.response.BasicResponse;
import com.water.wfo.sys.pojo.entity.MenuEntity;
import com.water.wfo.sys.pojo.request.RoleRequest;
import com.water.wfo.sys.pojo.response.MenuResponse;
import com.water.wfo.sys.pojo.response.RoleResponse;
import com.water.wfo.user.ability.MenuAbility;
import com.water.wfo.user.api.MenuApi;
import com.water.wfo.user.business.service.IMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * packageName com.water.wfo.user.controller
 *
 * @author
 * @className MenuController(处以class为网)
 * @date 2024/9/9
 * @description T0D0
 */
@Slf4j
@RestController
public class MenuController implements MenuApi {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private MenuAbility menuAbility;
    @Override
    public BasicResponse<MenuResponse> queryTreeInfo(@RequestBody RoleRequest request) {
        BasicResponse<MenuResponse> basicResponse = new BasicResponse<>();
        if(null == request){
            return basicResponse.buildFail("入参为空");

        }
        try {
            MenuResponse response= menuService.queryMenuTreeInfo(request);
            return basicResponse.buildSuccess(response);
        } catch (Exception e) {
            log.error("查询角色集合异常:",e);
            return  basicResponse.buildFail("查询客户集合异常");
        }
    }

    @Override
    public BasicResponse<String> addMenuInfo(@RequestBody MenuEntity menuEntity) {
        BasicResponse<String> basicResponse = new BasicResponse<>();
        if(null == menuEntity){
            return basicResponse.buildFail("入参为空");
        }
        try {
            menuAbility.insert(menuEntity);
            return basicResponse.buildSuccess();
        } catch (Exception e) {
            log.error("新增菜单异常:",e);
            return  basicResponse.buildFail(e.getMessage());
        }
    }

    @Override
    public BasicResponse<String> editeMenuInfo(@RequestBody MenuEntity MenuEntity) {
        BasicResponse<String> basicResponse = new BasicResponse<>();
        if(null == MenuEntity){
            return basicResponse.buildFail("入参为空");
        }
        try {
            menuAbility.update(MenuEntity);
            return basicResponse.buildSuccess();
        } catch (Exception e) {
            log.error("修改菜单异常:",e);
            return  basicResponse.buildFail(e.getMessage());
        }
    }
}
